<?php
include_once('visvc.php');
include_once('vmw_page.php');

date_default_timezone_set('America/Los_Angeles');
$vmware = null;

//
// Process an existing vmware session. If no session exists or the session
// has expired and $redirect is true then the user is redirected to the login
// page.
//
function vmware_session($redirect = true)
{
    global $vmware, $_COOKIE;

    if (isset($_COOKIE['vmw_Session']))
    {
        try
        {
            $vmware = new visvc('https://' . $_COOKIE['vmw_Host'] . '/sdk/vimService.wsdl');
            $vmware->SetSessionID($_COOKIE['vmw_Session']);
            $vmware->ListDatacenters();
        }
        catch (Exception $e)
        {
            setcookie('vmw_Session', '', time() - 3600);
            $vmware = null;
            header('Location: login.php');
            exit(0);
        }
    }
    else
    {
        header('Location: login.php');
        exit(0);
    }
}
?>
